package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.ILoginView;
import com.cloudsigns.factorymanager2.engineering.IView.IUploadPhotoView;
import com.cloudsigns.factorymanager2.engineering.model.LoginModel;
import com.cloudsigns.factorymanager2.engineering.utils.ImageManager;

import java.io.IOException;

/**
 * Created by tony on 2018/4/14.
 */

public class UploadPhotoPresenter {
    private IUploadPhotoView view;
    private android.os.Handler mHandler = new android.os.Handler();

    public UploadPhotoPresenter(IUploadPhotoView view) {
        this.view = view;

    }

    public void uploadPhtoto() {
        ImageManager.getInstance().uploadImage(view.getFilePath()
                , new ImageManager.IUploadCallBack() {

                    @Override
                    public void onFailure(final String desc) {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                view.upLoadPhotoFailed(desc);
                                view.hideLoading();
                            }
                        });
                    }

                    @Override
                    public void onResponse(final String url) throws IOException {
                        //需要在UI线程执行
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                view.upLoadPhotoSuccessed(url);
                                view.hideLoading();
                            }
                        });
                    }
                });
    }
}
